import request from '@/utils/request'
import { ArchiveVo, ArticleDetailsResp, ArticleVo, PageArticleReq } from './type'
import { PageDto } from '../type'

const api = '/v1//article'

/** 查询展示文章表列表数据 */
export const pageArticleVo = (reqData: PageArticleReq): Result<PageDto<ArticleVo>> => {
  return request({
    url: `${api}/page`,
    method: 'post',
    data: reqData
  })
}

/** 热文 */
export const hotArticles = (): Result<PageDto<ArticleVo>> => {
  return request({
    url: `${api}/page`,
    method: 'post',
    data: {
      pageNum: 1,
      pageSize: 5,
      type: 'HOT'
    }
  })
}

/** 文章详情 */
export const articleDetails = (id: any): Result<ArticleDetailsResp> => {
  return request({
    url: `${api}/details/${id}`,
    method: 'get'
  })
}

/** 归档列表 */
export const pageArchive = (query: any): Result<PageDto<ArchiveVo>> => {
  return request({
    url: `${api}/archive`,
    method: 'get',
    params: query
  })
}

/** 查询文章 */
export const getSearch = (keywords: string) => {
  return request({
    url: `${api}/search`,
    method: 'get',
    params: { keywords }
  })
}

/** 点赞 */
export const articleLike = (id: number) => {
  return request({
    url: `/v1/article-like/${id}`,
    method: 'get'
  })
}

/** 判断对应文章是都通过验证 */
export const articleReadVerifyQuery = (id: number): Result<boolean> => {
  return request({
    url: `/system/article/readVerify/${id}`,
    method: 'get'
  })
}
